package com.seecen.controller;

import com.seecen.common.BaseResponse;
import com.seecen.common.ResultUtils;
import com.seecen.exception.ErrorCode;
import com.seecen.pojo.entity.Order;
import com.seecen.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @program: allmaster-end
 * @description:
 * @author: HCZ
 * @create: 2025-10-17 14:18
 * @version: 1.0
 **/
@RestController
@Slf4j
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrderService orderService;

    
    // 创建订单
    @PostMapping("/create")
    public BaseResponse<?> createOrder(@RequestBody Map<String, Object> orderData) {
        log.info("Controller: 创建订单请求，订单数据: {}", orderData);
        return orderService.createOrder(orderData);
    }
    
    // 获取订单详情
    @GetMapping("/detail/{orderId}")
    public BaseResponse<?> getOrderDetail(@PathVariable Long orderId) {
        log.info("Controller: 获取订单详情请求，订单ID: {}", orderId);
        return orderService.getOrderDetail(orderId);
    }
    
    // 更新订单
    @PutMapping("/update/{orderId}")
    public BaseResponse<?> updateOrder(@PathVariable Long orderId, @RequestBody Map<String, Object> orderData) {
        log.info("Controller: 更新订单请求，订单ID: {}, 数据: {}", orderId, orderData);
        return orderService.updateOrder(orderId, orderData);
    }
    //查询订单
    @GetMapping("/list")
    public BaseResponse<?> queryOrder(@RequestParam Long userId) {
        log.info("查询用户订单请求，用户ID: {}", userId);
        return orderService.queryOrder(userId);
    }
    //删除订单
    @PostMapping("/delete")
    public BaseResponse<?> deleteOrder(@RequestParam Long orderId) {
        log.info("删除订单请求，订单ID: {}", orderId);
        return orderService.deleteOrder(orderId);
    }
}
